home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / staircase.lua < prev    next >
Text File  |  2004-01-29  |  7KB  |  194 lines

  1. -- bed  state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         local currentCharacter = getStateObjectFromID(msg.sender);
  7.         
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button;
  11.         local neverFail = CharacterAI.checkFailing(CharacterAI.NEVER_FAIL);
  12.         
  13.         if currentCharacter and (currentCharacter.timeForWork() or neverFail) then
  14.             button = addPieMenuButton("pm_gotoWork", "work");
  15.             button.addDescription(ACTIVITY, "work");
  16.         end
  17.         
  18.         if currentCharacter and (canLeave(currentCharacter) or neverFail) then
  19.             button = addPieMenuButton(getLeaveButtonText(this), "changeHouse", "active");
  20.             button.addDescription(NO_AI, "true");
  21.         end
  22.         
  23. --        if canGoTo(CITY, this) then
  24. --            button = addPieMenuButton("pm_gotoCity", "changeHouse");
  25. --        end
  26.         
  27.         
  28.         --button = addPieMenuButton("Einkaufen gehen", "shop"); -- no game play function yet
  29.         -- button.addDescription(ACTIVITY, "shop");
  30.         
  31.         --button = addPieMenuButton("pm_goOut", "out");
  32.         -- button.addDescription(ACTIVITY, "out");
  33.         
  34.         local otherCharacter = getOtherCharacter(currentCharacter);
  35.         if (otherCharacter and activityPossible(currentCharacter, "giveGift", otherCharacter)) then
  36.             button = addPieMenuButton("pm_goBuyGift", "gift");
  37.             button.addDescription(ACTIVITY, "buyGift");
  38.             button.addDescription(NO_AI, "true");
  39.         end;
  40.     end )
  41.     
  42.     -- go to work
  43.     onMsg("work", function(msg)
  44.         -- get the game object server
  45.         local gameObjectServer = getGameObjectServer();
  46.         -- get character who initiated this action
  47.         local character = getStateObjectFromID(msg.sender);
  48.         
  49.         local neverFail = CharacterAI.checkFailing(CharacterAI.NEVER_FAIL);
  50.         if (not character.timeForWork()) and (not neverFail) then
  51.             print("not time for work");
  52.             instantAbort(character, EMOTICON_CANNOT, "emoThink");
  53.             return
  54.         end
  55.         
  56.         -- if character is too unhappy: abort characters action
  57.         if instantAbortIfUnhappy(character, "work", this) then return end;
  58.         -- walk to the closest action point
  59.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  60.         if (actionPoint) then
  61.         -- get the walk state object
  62.             local wso = character.walkSO;
  63.             -- create state machine contexts
  64.             local wsoContext = StateMachineContext();
  65.             -- store the action point
  66.             wsoContext.storeData("actionPointName", actionPoint.getName());
  67.             if (wso.walkToActionPoint(actionPoint)) then
  68.                 wso.queueStateMachine("staircaseChar.goToWork", this, wsoContext);
  69.             else
  70.                 print("no path found");
  71.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  72.             end
  73.         else
  74.             print("no action point found");
  75.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  76.         end
  77.     end )
  78.     
  79.     -- go shopping
  80.     onMsg("shop", function(msg)
  81.         -- get the game object server
  82.         local gameObjectServer = getGameObjectServer();
  83.         -- get character who initiated this action
  84.         local character = getStateObjectFromID(msg.sender);
  85.         -- walk to the closest action point
  86.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  87.         if (actionPoint) then
  88.         -- get the walk state object
  89.             local wso = character.walkSO;
  90.             -- create state machine contexts
  91.             local wsoContext = StateMachineContext();
  92.             -- store the action point
  93.             wsoContext.storeData("actionPointName", actionPoint.getName());
  94.             if (wso.walkToActionPoint(actionPoint)) then
  95.                 wso.queueStateMachine("staircaseChar.goToShop", this, wsoContext);
  96.             else
  97.                 print("no path found (in staircase.lua onMsg shop)");
  98.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  99.             end
  100.         else
  101.             print("no action point found (in staircase.lua onMsg shop)");
  102.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  103.         end
  104.     end )
  105.     
  106.     -- go shopping
  107.     onMsg("out", function(msg)
  108.         -- get the game object server
  109.         local gameObjectServer = getGameObjectServer();
  110.         -- get character who initiated this action
  111.         local character = getStateObjectFromID(msg.sender);
  112.         -- walk to the closest action point
  113.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  114.         if (actionPoint) then
  115.         -- get the walk state object
  116.             local wso = character.walkSO;
  117.             -- create state machine contexts
  118.             local wsoContext = StateMachineContext();
  119.             -- store the action point
  120.             wsoContext.storeData("actionPointName", actionPoint.getName());
  121.             if (wso.walkToActionPoint(actionPoint)) then
  122.                 wso.queueStateMachine("staircaseChar.goToShop", this, wsoContext);
  123.             else
  124.                 print("no path found (in staircase.lua onMsg shop)");
  125.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  126.             end
  127.         else
  128.             print("no action point found (in staircase.lua onMsg shop)");
  129.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  130.         end
  131.     end )
  132.  
  133.  
  134.     -- go shopping
  135.     onMsg("gift", function(msg)
  136.         -- get the game object server
  137.         local gameObjectServer = getGameObjectServer();
  138.         -- get character who initiated this action
  139.         local character = getStateObjectFromID(msg.sender);
  140.         -- walk to the closest action point
  141.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  142.         if (actionPoint) then
  143.         -- get the walk state object
  144.             local wso = character.walkSO;
  145.             -- create state machine contexts
  146.             local wsoContext = StateMachineContext();
  147.             -- store the action point
  148.             wsoContext.storeData("actionPointName", actionPoint.getName());
  149.             if (wso.walkToActionPoint(actionPoint)) then
  150.                 wso.queueStateMachine("staircaseChar.goBuyGift", this, wsoContext);
  151.             else
  152.                 print("no path found (in staircase.lua onMsg gift)");
  153.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  154.             end
  155.         else
  156.             print("no action point found (in staircase.lua onMsg gift)");
  157.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  158.         end
  159.     end )
  160.     
  161.     
  162.     -- go shopping
  163.     onMsg("changeHouse", function(msg)
  164.         -- get the game object server
  165.         local gameObjectServer = getGameObjectServer();
  166.         -- get character who initiated this action
  167.         local character = getStateObjectFromID(msg.sender);
  168.         -- walk to the closest action point
  169.         local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  170.         if (actionPoint) then
  171.         -- get the walk state object
  172.             local wso = character.walkSO;
  173.             -- create state machine contexts
  174.             local wsoContext = StateMachineContext();
  175.             -- store the action point
  176.             wsoContext.storeData("actionPointName", actionPoint.getName());
  177.             wsoContext.storeData("activePart", not(msg.data == ""));
  178.             if (wso.walkToActionPoint(actionPoint)) then
  179.                 wso.queueStateMachine("staircaseChar.goToOtherHouse", this, wsoContext);
  180.             else
  181.                 print("no path found (in staircase.lua onMsg gift)");
  182.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  183.             end
  184.         else
  185.             print("no action point found (in staircase.lua onMsg gift)");
  186.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  187.         end
  188.     end )
  189.     
  190.     
  191.     
  192.             
  193. endStateMachine()
  194.